package com.hantanger.weblog.util;

import java.util.HashMap;
import java.util.Map;

public class ClassFactory {
	
	private static Map<String, Object> map = new HashMap<String, Object>();
	
	@SuppressWarnings("unchecked")
	public static <T> T getInstance(Class<T> clazz){
		T t = null;
		try {
			t = (T)map.get(clazz.getName());
			if(t == null){
				t = clazz.newInstance();
				map.put(clazz.getName(), t);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return t;
	}
}
